
<input type="hidden" name='url' id='url' value="<?php echo $this->Html->url( null, true ); ?>">
<div class="row">
 	<div class="col-md-12">
		<div class="page-header">
		  <h1>Turnos</h1>
		</div>

		<div class="row">
			<div class="col-md-6">							
				<div class="btn-group pull-left">
					<?php echo $this->Html->link(__('Nuevo', true), array('controller' => 'events', 'action' => 'add' ),array('class'=>'btn btn-default btn-ls')); ?> 			  
				    <a href="#" class="btn btn-default btn-ls" id='edit_bt'>Editar</a>
				</div>
			</div>

			<div class="col-md-6 ">	
				<!-- <form method='post' > -->
					<div class="input-group">
		      	<input type="text" name='keyword' id='keyword'  class="form-control" placeholder='Filtro por DNI'>
		      	<span class="input-group-btn">
		        	<button class="btn btn-default" id='search_bt' type="button">Buscar</button>
		      	</span>
				  </div>
				<!-- </form>				-->
			</div>

		</div>
		
		
		<br>
		<br>
		<div id="grid">
			<!-- <?php //echo $this->element('events/grid');?>		-->
			<table class="table table-hover table-striped table-bordered">
				<thead>
					<tr>
						<th>#</th>
						<!-- <th><?php echo $this->Paginator->sort('Category.name', 'Categoria'); ?></th> -->
						<th><?php echo $this->Paginator->sort('service_id', 'Servicio'); ?></th>
						<th><?php echo $this->Paginator->sort('Clients.last_name', 'Cliente'); ?></th>
						<th><?php echo $this->Paginator->sort('date', 'Fecha'); ?></th>
						<th><?php echo $this->Paginator->sort('time_from', 'Horario de Inicio'); ?></th>
						<th><?php echo $this->Paginator->sort('time_to', 'Horario de fin'); ?></th>
					</tr>
				</thead>
				<tbody>
					<?php foreach ($data as $item) :?>
						<tr>
							<td><input type="checkbox" name='client_ids[]' value="<?php echo $item['Events']['id']?>"></td>
							<td><?php echo $item['Services']['name']?></td>
							<td><?php echo $item['Clients']['last_name'].' '.$item['Clients']['first_name']?></td>
							<td><?php echo $item['Events']['date']?></td>
							<td><?php echo $item['Events']['time_from']?></td>
							<td><?php echo $item['Events']['time_to']?></td>
							<!--
								<td>
									<button type="button" class="btn btn-xs btn-primary"><i class="glyphicon glyphicon-eye-open"></i>View</button>
									<button type="button" class="btn btn-xs btn-success"><i class="glyphicon glyphicon-pencil"></i>Edit</button>
									<button type="button" class="btn btn-xs btn-danger"><i class="glyphicon glyphicon-remove"></i>Delete</button>
								</td>
							-->
						</tr>
					<?php endforeach;?>	
				</tbody>
			</table>
		  <ul class="pagination">
				<li><?php echo $this->Paginator->first('<i class="glyphicon glyphicon-step-backward"></i>&nbsp;', array('class'=>'disabled', 'escape'=>false)); ?></li>
				<li><?php echo $this->Paginator->prev('<i class="glyphicon glyphicon-backward"></i>&nbsp;', array('escape'=>false)) ;?></li>
				<li><?php echo $this->Paginator->numbers(array('separator'=>'')); ;?> </li>
				<li><?php echo $this->Paginator->next('<i class="glyphicon glyphicon-forward"></i>&nbsp;', array('escape'=>false)) ;?></li><li><?php echo $this->Paginator->last('<i class="glyphicon glyphicon-step-forward"></i>&nbsp;', array('class'=>'disabled','escape'=>false)); ?></li>				
			</ul>			
		</div>			
		

	</div> 
</div>

<script type="text/javascript">
	function get_check_id(){
	    var result=0;
	  //users_ids
	    $('input[name=client_ids\\[\\]]').each(function() {
	        if( $(this).is(":checked")){
	            var user_id = $(this).val();	           
	            result =  user_id;
	        }
	    });
	    return result;
	}




$(function()
{
	$("#keyword").keyup(function(){
		var keyword=$(this).val();
		var url='events/filter';
		$("#grid").load(url,{keyword:keyword});
	});
	$("#search_bt").click(function(){
		var keyword=$("#keyword").val();
		var url='events/filter';
		$("#grid").load(url,{keyword:keyword});	
	});
	var url=$("#url").val();
	$("#edit_bt").click(function(){
		chck_id= get_check_id();
		redirect_url=url+"/edit/"+chck_id
		window.location.replace(redirect_url);
		return false;
	});

	$("#history_bt").click(function(){
		chck_id= get_check_id();
		redirect_url=url+"/history/"+chck_id
		window.location.replace(redirect_url);
		return false;
	});
});
</script>

